import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:ls_work/ui/hand_over/hand_over_area_page.dart';
import 'package:ls_work/util/ext_utils.dart';
import 'package:ls_work/viewmodel/hand_over/new_hand_over_home_view_model.dart';

class NewHandOverHomePage extends BaseStatefulMvvmWidget {
  @override
  State<StatefulWidget> createState() => _NewHandOverHomeState();
}

class _NewHandOverHomeState
    extends BaseMvvmListState<NewHandOverHomeViewModel, NewHandOverHomePage> {
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text('交接班'),
      ),
      body: Column(
        children: [
          SizedBox(
            height: 12,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              CommonText('本周', textColor: Colors.white, textSize: 17)
                  .addToContainer(
                      decoration: BoxDecoration(
                          color: viewModel.queryType == 0
                              ? Colours.app_main
                              : Colors.grey,
                          borderRadius: 20.borderRadius),
                      padding:
                          EdgeInsets.symmetric(horizontal: 19, vertical: 8))
                  .onTap(() {
                viewModel.chooseQueryType(0);
              }),
              CommonText('上周', textColor: Colors.white, textSize: 17)
                  .addToContainer(
                      decoration: BoxDecoration(
                          color: viewModel.queryType == 1
                              ? Colours.app_main
                              : Colors.grey,
                          borderRadius: 20.borderRadius),
                      padding:
                          EdgeInsets.symmetric(horizontal: 19, vertical: 8))
                  .onTap(() {
                viewModel.chooseQueryType(1);
              }),
              CommonText('按月', textColor: Colors.white, textSize: 17)
                  .addToContainer(
                      decoration: BoxDecoration(
                          color: viewModel.queryType != 0 &&
                                  viewModel.queryType != 1
                              ? Colours.app_main
                              : Colors.grey,
                          borderRadius: 20.borderRadius),
                      padding:
                          EdgeInsets.symmetric(horizontal: 19, vertical: 8))
                  .onTap(() {
                viewModel.chooseQueryType(null);
              }),
            ],
          ),
          if (viewModel.queryType != 0 && viewModel.queryType != 1) ...[
            SizedBox(
              height: 12,
            ),
            Row(
              children: [
                CommonText(viewModel.chooseTimeStr, hintText: '请选择查询月份')
                    .setWeight(1),
                Icon(Icons.arrow_drop_down_sharp)
              ],
            ).onTap(() {
              viewModel.chooseQueryTime();
            }).addToContainer(
                decoration: BoxDecoration(
                  color: Colours.bg_color,
                  borderRadius: 20.borderRadius,
                ),
                margin: EdgeInsets.symmetric(horizontal: 20),
                padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12))
          ],
          loadingContentWidget.setWeight(1)
        ],
      ),
    );
  }

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        CommonText(
            item.reportDate!.changeTime(format: ['yyyy', '-', 'mm', '-', 'dd']),
            textSize: 17),


        CommonText(item.dutyTypeName),
        CommonText("(${item.startTime??""}-${item.endTime??""})"),
        CommonText(item.week),


        // Icon(Icons.keyboard_arrow_right_sharp)
      ],
    ).onTap(() {
      Go().push(HandOverAreaPage(info: item));
    }).addToContainer(
        padding: EdgeInsets.symmetric(horizontal: 15, vertical: 14));
  }

  @override
  Widget get separatorDivider => Gaps.dividerLine;

  @override
  NewHandOverHomeViewModel createViewModel() {
    return NewHandOverHomeViewModel(context);
  }
}
